<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'MyJsp.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<jsp:include page="/scripts/common/index.html"></jsp:include>
<jsp:include page="/scripts/dhtmlx/index.html"></jsp:include>
<jsp:include page="/scripts/jquery/index.html"></jsp:include>
<jsp:include page="/scripts/bootstrap/index.html"></jsp:include>
<link rel="stylesheet" href="${basepath }style/default.css">
</head>
<script type="text/javascript">
	var temp = false;
	var mygrid_tab_status;
	var orgTree, treeId;
	var fileGroupId;//文件组id
	function init() {
		
	}
	//修改的是当前员工信息
	function save() {
		$('#MyForm').bootstrapValidator('validate');
		if (temp) {
			$.ajax({
				type : 'POST' ,
				url : 'page/system/manage/Login/doRetrievePassword' ,
				data : $('#MyForm').serializeArray() ,
				dataType : "json" ,
				async : true ,
				cache : false ,
				jsonpCallback : "null" ,
				success : function(response, status, statusText) {
					if (response.status) {
						if (response.content == "修改成功！") {//type != 1
							//SN.clearFormValue("MyForm");
							SN.alert.info("修改成功！", function() {
								closeWindow();
							});
						} else if (response.content == "修改失败！") {
							//SN.clearFormValue("MyForm");
							SN.alert.info("修改失败！", function() {
							});
						}
					} else {
						SN.alert.info(response.content);
					}
				} ,
				error : function(response, status, statusText) {
					//alert(response + ":" + status + ":" + statusText);
				} ,
				complete : function(response, status, statusText) {
					//alert(response + ":" + status + ":" + statusText);
				}
			});
		}
	}
	var countdown = 30;
	function settime(val) {
		var telphone = $("#telphone").val();
		var userAccount = $("#userAccount").val();
		var re = /^1[3|5|8]{1}[0-9]{9}$/;
		 if(re.test(telphone)&&userAccount!=""&&userAccount!=null){
		        sendSMS(val);
				$.ajax({
					type : 'POST',
					url : 'page/system/manage/Login/doSendSMS',
					data :{"map.telphone":$("#telphone").val(),"map.userAccount":userAccount},
					dataType : "json",
					async : true,
					cache : false,
					jsonpCallback : "null",
					success : function(response, status, statusText) {
						//alert(response + ":" + status + ":" + statusText);
						if (response.status) {
							SN.alert.info(response.content);
						} else {
							SN.alert.info(response.content);
						}
					},
					error : function(response, status, statusText) {
						//alert(response + ":" + status + ":" + statusText);
					},
					complete : function(response, status, statusText) {
						//alert(response + ":" + status + ":" + statusText);
					}
				});
		}else{
			SN.alert.info("请输入正确的账号和手机号码！");
		}
	}
	function sendSMS(val){
		if (countdown == 0) {
			val.removeAttribute("disabled");
			$("#checkText").text("获取验证码");
			countdown = 30;
			clearTimeout(0);
			return;
		} else {
			val.setAttribute("disabled", true);
			$("#checkText").text("剩余(" + countdown + ")");
			countdown--;
		}
		setTimeout(function() {sendSMS(val)}, 1000)
	}
	//回到顶部按钮添加
	$(document).ready(function () {
            GP.goup({
                trigger: 100,
                bottomOffset: 30,
                locationOffset: 30,
                titleAsText: true,
               containerColor: '#7e7f7e'
            },"Panel_");
    });
		
	$(document).ready(function() {
		$('#MyForm').bootstrapValidator({
			message : 'This value is not valid' ,
			icon : {
				valid : 'glyphicon glyphicon-ok' ,
				invalid : 'glyphicon glyphicon-remove' ,
				validating : 'glyphicon glyphicon-refresh'
			} ,
			fields : {
				"map.userAccount" : {
					row : '.col-xs-6' ,
					validators : {
						notEmpty : {
							message : '登录名不能为空'
						} ,
						regexp : {
							regexp : /^([a-zA-Z0-9]{5,12})$/ ,
							message : '长度为5-12英文'
						}
					}
				},
				"map.telphone" : {
					row : '.col-xs-6' ,
					validators : {
						notEmpty: {
	                         message: '手机号码不能为空'
	                     },
	                     regexp: {
	                         regexp: /^1[3|5|8]{1}[0-9]{9}$/,
	                         message: '请输入长度为11位正确的手机号码'
	                     }
					}
				},
				"map.VerificationCode" : {
					row : '.col-xs-6' ,
					validators : {
						notEmpty: {
	                         message: '验证码不能为空'
	                     }
					}
				},
				"map.password": {
					row : '.col-xs-6' ,
					validators : {
						notEmpty : {
							message : '密码不能为空'
						} ,
						regexp : {
							regexp : /^[a-zA-Z0-9_]{6,10}$/ ,
							message : '由6-10位数字英文或者下划线组成 '
						}
					}
	             },
	            "secondPassword" : {
	            	row : '.col-xs-6' ,
	            	 validators: {
	            		 notEmpty : {
								message : '密码不能为空'
							} ,
	                    identical: {
	                        field: 'map.password',
	                        message: '与新密码不一致'
	                    }
	                }
				}
			}
		}).on('success.form.bv', function(e) {
			//alert("验证成功");
			temp = true;
			return temp;
		}).on('error.form.bv', function(e) {
			SN.alert.info("验证失败");
			temp = false;
			return temp;
		});
	});

</script>

<script type="text/javascript">
	function closeWindow() {
		parent.w1.close();
	}
</script>

<body onload="init()" marginleft="0" margintop="0" style="margin: 0px;border: 0">
	<form class="form-horizontal MyForm" id="MyForm" name="MyForm" method="post" target="MyFrame" enctype="multipart/form-data">
 
		<table class="contTable">
			<tr style="height:auto">
				<td valign="top">
					<div id="Panel_" style="width:100%;height:330px;overflow-y:auto;">
						<div class="blockBorder">
							<div class="tableCont" style="width: 90%;">
								<div class="form-group">
									<label class="col-xs-3 control-label" for="userAccount">登录名:</label>
									<div class="col-xs-6 ">
										<input class=" form-control" name="map.userAccount" id="userAccount" value="${map.userAccount }" type="text" placeholder="请输入登录名" />
									</div>
									<div class="col-xs-1 ">
										<span class="required">*</span>
									</div>
								</div>
								<div class="form-group">
									<label class="col-xs-3 control-label" for="telphone">手机号码:</label>
									<div class="col-xs-6 ">
										<input class=" form-control" name="map.telphone" id="telphone" value="${map.telphone }" type="text" placeholder="请输入注册手机号" />
									</div>
									<div class="col-xs-1 ">
										 <span class="required">*</span>
									</div>
								</div>
								<div class="form-group" >
									<label class="col-xs-3 control-label" for="VerificationCode">验证码:</label>
									<div class="col-xs-6 ">
										<input class=" form-control" name="map.VerificationCode" id="VerificationCode" value="${map.VerificationCode }" type="text" placeholder="请输入手机验证码" />
									</div>
									<div class="col-xs-1 ">
										
										<button type="button" class="btn btn-primary" style="width:80px;" onclick="settime(this)" ><span id="checkText">获取验证码</span></button>
									</div>
								</div>
								<div class="form-group">
									<label class="col-xs-3 control-label" for="password">新密码:</label>
									<div class="col-xs-6">
										<input class="form-control" name="map.password" id="password" value="" type="input" onfocus="this.type='password'" placeholder="请输入新密码" />
									</div>
									<div class="col-xs-1 ">
										<span class="required">*</span>
									</div>
								</div>
								<div class="form-group">
									<label class="col-xs-3 control-label" for="secondPassword">确认密码:</label>
									<div class="col-xs-6">
										<input class="form-control" name="secondPassword" id="secondPassword" value="" type="input" onfocus="this.type='password'" placeholder="请确认密码" />
									</div>
									<div class="col-xs-1 ">
										<span class="required">*</span>
									</div>
								</div>
								<hr style="width:100%;border:1px solid #dbdbdb;">
								<div class="form-group" style="margin-top: 20px;">
									<div class="col-xs-5" style="margin: auto;float: right;">
										<button onclick="save()" class="btn btn-primary" type="button">
											<span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>&nbsp;<span>保存</span>
										</button>
										<button onclick="" class="btn btn-primary" type="reset">
											<span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>&nbsp;<span>重置</span>
										</button>
									</div>
								</div>
							</div>
						</div>
						
					</div>
				</td>
			</tr>
		</table>
	</form>
</body>
</html>
